package com.dhl.cloud.course.service;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dhl.cloud.common.util.DateUtils;
import com.dhl.cloud.course.dao.NoticeMapper;
import com.dhl.cloud.course.entity.Notice;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class NoticeService {
	@Autowired
	private NoticeMapper noticeMapper;
 
	public List<Notice> selectBycourseid(Integer courseid) {
		return noticeMapper.selectBycourseid(courseid);
	}
	
	public PageInfo<Notice> selectSysNoticeList(Integer pageNum,Integer pageSize) {
		PageHelper.startPage(pageNum,pageSize);
		List<Notice> list =  noticeMapper.selectSysNoticeList();
		PageInfo<Notice> pageInfo = new PageInfo<>(list);
		return pageInfo;
	}
	public List<Notice> selectSysNoticeListLimit() {
		return noticeMapper.selectSysNoticeListLimit();
	}
	public List<Notice> selectAllCourseNoticeList() {
		return noticeMapper.selectAllCourseNoticeList();
	}
	public int deleteByPrimaryKey(Integer id) {
		return noticeMapper.deleteByPrimaryKey(id);
	}
	
	public int insert(Notice c) {
		if (c.getId() != null)
		{
			Notice cc = noticeMapper.selectByPrimaryKey(c.getId());
			cc.setTitle(c.getTitle());
			cc.setContent(c.getContent());
			cc.setModifytime(DateUtils.getDateTime());
			return noticeMapper.updateByPrimaryKey(cc);
		}
		else
		{
			c.setCreatetime(DateUtils.getDateTime());
			return noticeMapper.insert(c);
		}
		
	}
}
